/*
 * @Author: moeWang
 * @Date: 2022-03-03 17:49:42
 * @LastEditTime: 2022-03-04 16:22:43
 * @LastEditors: moeWang
 * @Description:
 * @FilePath: \nest-web\src\decorator\api-request.decorator.ts
 */

import { Type } from '@nestjs/common';
import { ApiBody, getSchemaPath } from '@nestjs/swagger';
import { AccountIdModel } from 'src/logical/account/models/accountId.model';
import { Pagination } from 'src/logical/common/models/Pagination.model';

export const ApiQueryBodyRequest = <TModel extends Type<any>>(
  name: string,
  model: TModel,
) => {
  return {
    // name,
    // type: 'object',
    // in: 'header',
    schema: {
      title: name,
      allOf: [
        {
          properties: {
            pagination: {
              $ref: getSchemaPath(Pagination),
            },
            query: {
              $ref: getSchemaPath(model),
            },
          },
        },
      ],
    },
  };
};

export const ApiFile =
  (fileName: string = 'file'): MethodDecorator =>
  (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
    ApiBody({
      schema: {
        type: 'object',
        properties: {
          [fileName]: {
            type: 'string',
            format: 'binary',
          },
        },
      },
    })(target, propertyKey, descriptor);
  };
